//
//  ColorChangeView.m
//  WULIHH
//
//  Created by tang on 16/3/31.
//  Copyright © 2016年 tang. All rights reserved.
//

#import "ColorChangeView.h"
#import "Header.h"

#import "AlphaSlider.h"
#import "CustomCell.h"

@interface ColorChangeView ()<UITableViewDataSource, UITableViewDelegate, CustomCellDelegate>
{
    UITableView *mainTableView;
    NSArray *_colorArr;
    NSArray *colorTextArray;
}

@end


@implementation ColorChangeView



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _colorArr = @[@"baise",@"heise",@"fense",@"lanse",@"huangse",@"hongse",@"lvse"];
        colorTextArray = @[@"ffffff", @"000000", @"f76394", @"00bff3", @"fcbe32", @"ed1c24", @"469637"];
        [self setUserInteractionEnabled:YES];
        [self initUI];
        
    }
    return self;
}


- (void)initUI
{
    UILabel *lable1 = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 29.0, 45.0, 10.0)];
    [lable1 setTextAlignment:NSTextAlignmentLeft];
    [lable1 setTextColor:uicolor(153, 153, 153)];
    [lable1 setText:@"文字颜色"];
    [lable1 setFont:[UIFont systemFontOfSize:10.0]];
    [self addSubview:lable1];
    
    mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 50,biliwith(210.0))];
    [self addSubview:mainTableView];
    [mainTableView setBackgroundColor:[UIColor clearColor]];
    
    [mainTableView setDataSource:self];
    [mainTableView setDelegate:self];
    [mainTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [mainTableView setTransform:CGAffineTransformMakeRotation(-M_PI / 2.0)];
    [mainTableView setShowsVerticalScrollIndicator:NO];

    
    UILabel *lable2 = [[UILabel alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(lable1.frame)+26.0, 55.0, 10.0)];
    [lable2 setTextColor:uicolor(153, 153, 153)];
    [lable2 setFont:[UIFont systemFontOfSize:10.0]];
    [lable2 setText:@"气泡透明度"];
    [self addSubview:lable2];
    
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(87.0, 52.0, WithView-21-87, 40)];
    [self addSubview:slider];
    [slider setBackgroundColor:[UIColor clearColor]];
    [slider setMaximumValue:1.0];
    [slider setMinimumValue:0.0];
//    [slider setThumbImage:[UIImage imageNamed:@"Ellipse.png"] forState:UIControlStateNormal];
//    [slider setThumbImage:[UIImage imageNamed:@"Ellipse.png"] forState:UIControlStateHighlighted];
    
    [slider setMaximumTrackImage:[UIImage imageNamed:@"xingzhuang.png"] forState:UIControlStateNormal];
    [mainTableView setCenter:CGPointMake(slider.center.x, 30)];
    
    [slider addTarget:self action:@selector(changeAlpha:) forControlEvents:UIControlEventValueChanged];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 7;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 40;
    
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *identifier = @"identifier";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        
    }
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    [cell setMCustomCellDelegate:self];
    [cell.btn setBackgroundImage:[UIImage imageNamed:_colorArr[indexPath.row]] forState:UIControlStateNormal];
//    [Cell.btn setBackgroundImage:[UIImage imageNamed:_colorArr[indexPath.row]] forState:UIControlStateHighlighted];
//    [Cell.btn setBackgroundImage:[UIImage imageNamed:_colorArr[indexPath.row]] forState:UIControlStateSelected];
    cell.btn.tag = indexPath.row;
//    [cell setBackgroundColor:[UIColor redColor]];
    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    NSLog(@"%@", colorTextArray[indexPath.row]);
    [_MColorChangeViewDelegate changeTextColor:colorTextArray[indexPath.row]];
}


- (void)selectTag:(int)tag
{
    [_MColorChangeViewDelegate changeTextColor:colorTextArray[tag]];
}



- (void)changeAlpha:(UISlider *)sender
{
//    NSLog(@"%f", sender.value);
    [_MColorChangeViewDelegate changeAlpha:sender.value];
}






/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
